package com.wing.bill.controller.admin;

import cn.hutool.core.date.DatePattern;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ReportUtil {
    //当前时间往前推一个月
    public static List<LocalDateTime> dateUtil() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusMonths(-1), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //当前时间往前推一周
    public static List<LocalDateTime> weekUtil() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusWeeks(-1), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //当天
    public static List<LocalDateTime> dayUtil() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }

    //当月
    public static List<LocalDateTime> monthUtil() {//开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }

    //当周
    public static List<LocalDateTime> thisWeekUtil() {//开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay();
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }

    //往前推99天 包括当天  一起100天
    public static List<LocalDateTime> hundredDays() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusDays(-99), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }

    //往前推N-1天 包括当天  一起N天
    public static List<LocalDateTime> days(Integer n) {
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusDays(1-n), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }

    // 获取N天的集合
    public static List<String> getTenDaysList(Integer days) {
        List<String> list = new ArrayList<>();
        for (int i = days - 1; i >= 0; i--) {
            if(i == 0){
                list.add(LocalDate.now().toString());
            }else{
                list.add(LocalDate.now().plusDays(0-i).toString());
            }
        }
        return list;
    }

    //昨天
    public static List<LocalDateTime> yesterday() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusDays(-1), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now().plusDays(-1), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //上周一到上周日
    public static List<LocalDateTime> weekOld() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusWeeks(-1).with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //上一月
    public static List<LocalDateTime> dateUtilOld() {//当天开始时间00 00 00 到 23 59 59
        LocalDateTime first = LocalDateTime.of(LocalDate.now().plusMonths(-1).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(LocalDate.now().plusMonths(-1).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //指定的一天
    public static List<LocalDateTime> oneDay(String createTime)  {//当天开始时间00 00 00 到 23 59 59
        LocalDate parseLocalDate = LocalDate.parse(createTime, DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN));
        LocalDateTime first = LocalDateTime.of(parseLocalDate, LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(parseLocalDate, LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
    //指定一天的前一天
    public static List<LocalDateTime> oneDayOld(String createTime)  {//当天开始时间00 00 00 到 23 59 59
        LocalDate parseLocalDate = LocalDate.parse(createTime, DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN));
        LocalDateTime first = LocalDateTime.of(parseLocalDate.plusDays(-1), LocalTime.MIN);
        LocalDateTime last = LocalDateTime.of(parseLocalDate.plusDays(-1), LocalTime.MAX);
        List list = new ArrayList<>();
        list.add(first);
        list.add(last);
        return list;
    }
}
